<%@ page language='java' contentType='text/html; charset=UTF-8' %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
<body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>
<div>
    账号：<input type="text" id="user">
    密码：<input type="text" id="pwd">
    <button id="login">登录</button>
</div>
<div>
    内容：<input type="text" id="text">
    接收人：<input type="text" id="receive">
    <button id="send">发送</button>
</div>
<div>
    <div id="questIdText"></div>
    <button id="questId">获取信息</button>
</div>
<div>
    <input type="text" id="setDemandId">
    <button id="setDemand">选中方案</button>
</div>
<script>
    let ws;
    $("#login").click(data=>{
        $.ajax({
            url:"/login",
            data:{
                pwd:$("#pwd").val(),
                user:$("#user").val()
            },
            type:"post",
            success:data=>{
                ws = new WebSocket("ws://localhost:80/timely");
                ws.onopen = open=>{
                    console.log("打开scoket");
                };
                ws.onmessage = onmessage=>{
                    console.log(onmessage);
                };
            }
        });
    });
    $("#send").click(()=>{
        $.ajax({
            url:"/addMes",
            type:"post",
            data:{
                toId:$("#receive").val(),
                text:$("#text").val()
            },
            success:data=>{
                console.log(data)
            }
        });
    })
    $("#questId").click(data=>{
        $.ajax({
            url:"/initDemandData",
            type:"post",
            data:{
                pageSize:1,
                num:10
            },
            success:data=>{
                $("#questIdText").text(JSON.stringify(data));
            }
        });
    });
    $("#setDemand").click(function () {
        $.ajax({
            url:"/responseDemand",
            type:"post",
            data:{
                setId:$("#setDemandId").val()
            },
            success:data=>{
                console.log(data)
            }
        });
    });
</script>
</body>
</html>
